package com.leeon.container;

import java.util.*;

import static net.mindview.util.Print.print;

public class ListFeaturesString {

    public static List<String> generatorList(int size){
        String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        Random random = new Random();
        List<String> list = new ArrayList<String>(size);
        for (int i = 0; i < size; i++) {
            list.add(String.valueOf(str.charAt(random.nextInt(62))));
        }
        return list;
    }

    public static String generatorString(){
        Random random = new Random();
        String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        return String.valueOf(str.charAt(random.nextInt(62)));
    }

    public static void main(String[] args){
        Random random = new Random(47);
        List<String> strings = generatorList(10);
        System.out.println("1:" + strings);
        String h = generatorString();
        strings.add(h);
        System.out.println("2:" + strings);
        System.out.println("3:" + strings.contains(h));
        strings.remove(h);
        String p = strings.get(2);
        System.out.println("4" + p + " " + strings.indexOf(p));
        String cymric = generatorString();
        System.out.println("5: " + strings.indexOf(cymric));
        System.out.println("6: " + strings.remove(cymric));
        System.out.println("7: " + strings.remove(p));
        System.out.println("8: " + strings);
        strings.add(3,generatorString());
        System.out.println("9: " + strings);
        List<String> sub = strings.subList(1,4);
        System.out.println("sublist : " + sub);
        System.out.println("10: " + strings.containsAll(sub));
        Collections.sort(sub);
        System.out.println("sorted sublist: " + sub);
        System.out.println("11: " + strings.containsAll(sub));
        Collections.shuffle(sub,random);
        print("shuffled sublist : " + sub);
        print("12 : " + strings.containsAll(sub));
        List<String> copy = new ArrayList<String>();
        sub = Arrays.asList(strings.get(1),strings.get(4));
        print("sub: " + sub);
        copy.retainAll(sub);
        print("13: " + copy);
        copy = new ArrayList<String>(strings);
        print("13-1 : " + copy);
        copy.remove(2);
        print("14 : " + copy);
        print("14-1 : " + sub);
        copy.removeAll(sub);
        print("15: " + copy);
        copy.set(1,generatorString());
        print("16: " + copy);
        copy.addAll(2,sub);
        print("17: " + copy);
        print("18: " + strings.isEmpty());
        strings.clear();
        print("19: " + strings);
        print("20: " + strings.isEmpty());
        strings.addAll(generatorList(5));
        print("21: " + strings);
        Object[] o = strings.toArray();
        print("22: " + o[3]);
        String[] pa = strings.toArray(new String[2]);
        print("23: "+ pa[3]);
    }
}
